﻿using Afterbunny.UI.WPF.Core;
using CygiaLog.Module;
using DistributedVisionRunner.Module;
using InProcessTests.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using CygiaLog.Module.RollingFileAppender;
using Prism.Events;

namespace InProcessTests
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        protected override Window CreateShell()
        {
            var rm = Container.Resolve<IRegionManager>();
            rm.RegisterViewWithRegion(Constants.RegionName_TestRegion, typeof(TestView));

            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            CygiaLogModule.ConfigModule(new List<AppenderParam> { new AppenderParam("General", Path.Combine(DistributedVisionRunner.Module.Constants.AppDataDir, "Log")) }, Constants.RegionName_LogRegion);
            moduleCatalog.AddModule<CygiaLogModule>();

            // Log messages from DistributedVisionRunnerModule
            var ea = Container.Resolve<IEventAggregator>();
            Action<LogItem> logMethod =
                logItem =>
                    ea.GetEvent<LogEvent>().Publish(("General", logItem));

            DistributedVisionRunnerModule.ConfigureModule(logMethod, Constants.RegionName_ProcessRegion, false);
            DistributedVisionRunnerModule.SetDefaultImageBackground(Theme.PrimaryColor.R, Theme.PrimaryColor.G, Theme.PrimaryColor.B);
            moduleCatalog.AddModule<DistributedVisionRunnerModule>();

            base.ConfigureModuleCatalog(moduleCatalog);
        }

      
    }
}
